/**
 * @Date: Mar 3, 2010 5:47:54 PM
 */
package com.philip.journal.core.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.philip.journal.core.service.ServiceProxy;

/**
 * The base class that needs to be inherited by every action controller in the application.
 *
 * @author cry30
 */
public abstract class BaseAction implements ControllerAction {//NOPMD

    /** Subclass reusable logger instance. */
    private final Logger logger = Logger.getLogger(getClass()); //NOPMD

    /**
     * Service proxy to be accessed by sub class.
     */
    private final transient ServiceProxy serviceProxy;

    /** Response handler. */
    private transient ResponseHandler responseHandler;

    /** Standard java Servlet request. */
    private transient HttpServletRequest servletRequest;

    /** Standard java Servlet response. */
    private transient HttpServletResponse servletResponse;

    protected HttpServletRequest getHttpServletRequest() {
        return servletRequest;
    }

    public void setHttpServletRequest(final HttpServletRequest pServletRequest) {
        this.servletRequest = pServletRequest;
    }

    protected HttpServletResponse getHttpServletResponse() {
        return servletResponse;
    }

    /**
     * Accessor method.
     *
     * @param pServletResponse standard servlet response.
     */
    public final void setHttpServletResponse(final HttpServletResponse pServletResponse) {
        this.servletResponse = pServletResponse;
    }

    /**
     * Default and only constructor. Sub class must also call this.
     *
     * @param pServiceProxy Service proxy to be injected by Spring.
     * @param pResponseHandler Response handler to be injected by Spring.
     */
    protected BaseAction(final ServiceProxy pServiceProxy, final ResponseHandler pResponseHandler) {
        this.serviceProxy = pServiceProxy;
        this.responseHandler = pResponseHandler;
    }

    @Override
    public final ResponseHandler getResponseHandler() {
        return responseHandler;
    }

    @Override
    public final void setSessionId(final String sessionId) {
        getServiceProxy().setSessionId(sessionId);
    }

    /**
     * @see BaseAction#logger.
     * @return the logger
     */
    public final Logger getLogger() {
        return logger;
    }

    /**
     * Accessor method for sub classes use only.
     *
     * @return the serviceProxy
     */
    protected ServiceProxy getServiceProxy() {
        return serviceProxy;
    }

    /**
     * @param pResponseHandler the responseHandler to set
     */
    public void setResponseHandler(final ResponseHandler pResponseHandler) {
        this.responseHandler = pResponseHandler;
    }
}
